package com.netstar.property;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.json.JSONException;

public abstract class DateProperty extends PrimitiveProperty {
	public abstract void set(Property obj, Date val);

	public abstract Date get(Property obj);

	public DateProperty() {
	}

	@Override
	public void copy(Property lhs, Property rhs) {
		set(lhs, get(rhs));
	}

	static DateFormat p = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

	@Override
	public void parse(Property obj, Object value) throws JSONException,
			IOException {
		try {
			long seconds = Long.parseLong(value.toString());
			long millisecs = seconds * 1000;
			Date date = new Date(millisecs);
			set(obj, date);
		} catch (Exception e) {
			set(obj, (Date) null);
		}
	}

}
